//
//  ZYCTeachingLearnChoiceView.m
//  ZDSC
//
//  Created by ZDTX on 2021/9/1.
//

#import "ZYCTeachingLearnChoiceView.h"
#import "ZYCTeachLearningPaperModel.h"
#import "NSString+Size.h"
@interface ZYCTeachingLearnChoiceView  ()

@property (nonatomic, strong) UIImageView *statusImageView;

@end

@implementation ZYCTeachingLearnChoiceView

-(void) setSelected:(BOOL)selected{
    _selected = selected;
    if (selected) {
        if (self.subjectType == 1) {
            _statusImageView.image = [UIImage imageNamed:@"xz"];
        }else{
            _statusImageView.image = [UIImage imageNamed:@"fxz"];
        }
    }else{
        if (self.subjectType == 1) {
            _statusImageView.image = [UIImage imageNamed:@"wxx"];
        }else{
            _statusImageView.image = [UIImage imageNamed:@"xzz"];
        }
    }
    
}

//subjectType 题目类型（1：单选题；2：多选题；3：简答题）
- (void)setSubjectType:(NSInteger)subjectType{
    _subjectType = subjectType;
    if (subjectType == 1) {
        _statusImageView.image = [UIImage imageNamed:@"wxx"];
    }else{
        _statusImageView.image = [UIImage imageNamed:@"xzz"];
    }
}
- (void)setModel:(ZYCAnswerModel *)model{
    _model = model;
    _titleLabel.text = model.content;
//    if (model.isSelect) {
//        if (self.subjectType == 1) {
//            _statusImageView.image = [UIImage imageNamed:@"xz"];
//        }else{
//            _statusImageView.image = [UIImage imageNamed:@"fxz"];
//        }
//    }else{
//        if (self.subjectType == 1) {
//            _statusImageView.image = [UIImage imageNamed:@"wxx"];
//        }else{
//            _statusImageView.image = [UIImage imageNamed:@"xzz"];
//        }
//    }



}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        tap.numberOfTouchesRequired = 1;
        tap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:tap];
        [self addSubview:self.statusImageView];
        [self addSubview:self.titleLabel];
        [self.statusImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15.0f);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(14.0f, 14.0f));
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.right.equalTo(self);
            make.left.equalTo(self.statusImageView.mas_right).offset(5.0f);
        }];
            
    }
    return self;
}

- (UIImageView *)statusImageView {
    if (!_statusImageView) {
        _statusImageView = [[UIImageView alloc] init];
    }
    return _statusImageView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 16.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

-(void) tapAction:(UITapGestureRecognizer *)recognizer{
    if ([self.delegate respondsToSelector:@selector(choiceView:didChoiceOptionId:)]) {
        [self.delegate choiceView:self didChoiceOptionId:self.model];
    }
}
@end
